//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _ACTIONSTATE_H
#define _ACTIONSTATE_H
//
#include <QObject>
//
class QAction;
class ActionDispatcher;
class ActionState:public QObject
{
   Q_OBJECT
   Q_DISABLE_COPY(ActionState)
   friend class ActionDispatcher;
//construction
public:
   ActionState(ActionDispatcher *disp=0,QAction *action=0,QObject *parent=0);
   ~ActionState();
//signals
signals:
   void triggered(bool checked=false);
//slots
public slots:
   void activate();
   void deactivate();
//management
public:
   void attach(ActionDispatcher *disp,QAction *action);
   void detach();
   bool is_attached() const;
   bool is_active() const;
//state
public:
   bool get_enabled() const
      {return enabled;}
   void set_enabled(bool enabled);
   bool get_checked() const
      {return checked;}
   void set_checked(bool checked);
private:
   bool enabled;
   bool checked;
//implementation
protected:
   ActionDispatcher *get_dispatcher() const
      {return dispatcher;}
   QAction *get_action() const
      {return action;}
   virtual void set_active();
   virtual void set_inactive();
   virtual void force_detach();
private:
   ActionDispatcher *dispatcher;
   QAction *action;
   bool active;
   void emit_triggered(bool checked=false);
};
//
#endif